home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / wc_ToggleB.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  10.2 KB  |  279 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         wc_ToggleB.c
  5. * RCS:          $Header: wc_ToggleB.c,v 1.3 91/03/14 03:15:26 mayer Exp $
  6. * Description:  XM_TOGGLE_BUTTON_WIDGET_CLASS/XM_TOGGLE_BUTTON_GADGET_CLASS
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sat Oct 28 04:56:30 1989
  9. * Modified:     Thu Oct  3 22:43:58 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: wc_ToggleB.c,v 1.3 91/03/14 03:15:26 mayer Exp $";
  42.  
  43. #include <stdio.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/ToggleB.h>
  46. #include <Xm/ToggleBG.h>
  47. #include "winterp.h"
  48. #include "user_prefs.h"
  49. #include "xlisp/xlisp.h"
  50. #include "w_funtab.h"
  51.  
  52.  
  53. extern Widget Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(); /* w_classes.c */
  54.  
  55.  
  56. /******************************************************************************
  57.  * typedef struct
  58.  * {
  59.  *    int reason;
  60.  *    XEvent * event;
  61.  *    int set;
  62.  * } XmToggleButtonCallbackStruct;
  63.  ******************************************************************************/
  64. static LVAL s_CALLBACK_SET;
  65. static void Lexical_Bindings_For_XmToggleButtonCallbackStruct(bindings_list, lexical_env, cd, o_widget)
  66.      LVAL bindings_list;    /* a list of symbols to which values from XmToggleButtonCallbackStruct are bound */
  67.      LVAL lexical_env;        
  68.      XmToggleButtonCallbackStruct* cd;
  69.      LVAL o_widget;        /* XLTYPE_WIDGETOBJ */
  70. {
  71.   extern LVAL s_CALLBACK_WIDGET, s_CALLBACK_REASON, s_CALLBACK_XEVENT; /* w_callbacks.c */
  72.   extern LVAL Wcb_Get_Callback_Reason_Symbol();    /* w_callbacks.c */
  73.   extern LVAL true;
  74.   register LVAL s_bindname;
  75.  
  76.   for ( ; consp(bindings_list); bindings_list = cdr(bindings_list)) {
  77.  
  78.     s_bindname = car(bindings_list);
  79.  
  80.     if (s_bindname == s_CALLBACK_WIDGET) {
  81.       xlpbind(s_bindname, o_widget, lexical_env);
  82.     }
  83.     else if (s_bindname == s_CALLBACK_REASON) {
  84.       xlpbind(s_bindname, Wcb_Get_Callback_Reason_Symbol(cd->reason), lexical_env);
  85.     }
  86.     else if (s_bindname == s_CALLBACK_XEVENT) {
  87.       xlpbind(s_bindname, (cd->event) ? cv_xevent(cd->event) : NIL, lexical_env);
  88.     }
  89.     else if (s_bindname == s_CALLBACK_SET) {
  90.       xlpbind(s_bindname, (cd->set) ? true : NIL, lexical_env);
  91.     }
  92.     else {
  93.       extern char temptext[];    /* from winterp.c */
  94.       sprintf(temptext,
  95.           "Unknown binding name in XmToggleButtonCallbackStruct callback evaluator. Valid symbols are [%s %s %s %s].",
  96.           (char*) getstring(getpname(s_CALLBACK_WIDGET)),
  97.           (char*) getstring(getpname(s_CALLBACK_REASON)),
  98.           (char*) getstring(getpname(s_CALLBACK_XEVENT)),
  99.           (char*) getstring(getpname(s_CALLBACK_SET)));
  100.       xlerror(temptext, s_bindname);
  101.     }
  102.   }
  103. }
  104.  
  105.  
  106. /******************************************************************************
  107.  * This is called indirectly via XtAddCallback() for callbacks returning
  108.  * an XmToggleButtonCallbackStruct as call_data.
  109.  ******************************************************************************/
  110. static void XmToggleButtonCallbackStruct_Callbackproc(widget, client_data, call_data)
  111.      Widget    widget;
  112.      XtPointer client_data;
  113.      XtPointer call_data;
  114. {
  115.   extern void Wcb_Meta_Callbackproc(); /* w_callbacks.c */
  116.  
  117.   Wcb_Meta_Callbackproc(client_data, call_data,
  118.             Lexical_Bindings_For_XmToggleButtonCallbackStruct,
  119.             NULL);
  120. }
  121.  
  122.  
  123. /******************************************************************************
  124.  * Same as WIDGET_CLASS's :add_callback method except that this understands
  125.  * how to get values from the XmToggleButtonCallbackStruct.
  126.  * Specifying one or more of the following symbols in the callback bindings 
  127.  * list will bind that symbol's value in the lexical environment of the callback:
  128.  * CALLBACK_WIDGET
  129.  * CALLBACK_REASON
  130.  * CALLBACK_XEVENT
  131.  * CALLBACK_SET
  132.  ******************************************************************************/
  133. LVAL Xm_Toggle_Button_Widget_Class_Method_ADD_CALLBACK()
  134. {
  135.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  136.  
  137.   return (Wcb_Meta_Method_Add_Callback(XmToggleButtonCallbackStruct_Callbackproc, FALSE));
  138. }
  139.  
  140.  
  141. /******************************************************************************
  142.  * Same as WIDGET_CLASS's :set_callback method except that this understands
  143.  * how to get values from the XmToggleButtonCallbackStruct.
  144.  * Specifying one or more of the following symbols in the callback bindings 
  145.  * list will bind that symbol's value in the lexical environment of the callback:
  146.  * CALLBACK_WIDGET
  147.  * CALLBACK_REASON
  148.  * CALLBACK_XEVENT
  149.  * CALLBACK_SET
  150.  ******************************************************************************/
  151. LVAL Xm_Toggle_Button_Widget_Class_Method_SET_CALLBACK()
  152. {
  153.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  154.  
  155.   return (Wcb_Meta_Method_Add_Callback(XmToggleButtonCallbackStruct_Callbackproc, TRUE));
  156. }
  157.  
  158.  
  159. /******************************************************************************
  160.  * (send <togglebutton> :GET_STATE)
  161.  * ==> returns T if button is set, NIL if not.
  162.  * 
  163.  * Boolean XmToggleButtonGetState (Widget w);
  164.  * Boolean XmToggleButtonGadgetGetState (Widget w);
  165.  ******************************************************************************/
  166. LVAL Xm_Toggle_Button_Widget_Class_Method_GET_STATE()
  167. {
  168.   LVAL self;
  169.   Widget widget_id;
  170.   extern LVAL true;
  171.  
  172.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  173.   xllastarg();
  174.  
  175.   return (XmToggleButtonGetState(widget_id) ? true : NIL);
  176. }
  177.  
  178. LVAL Xm_Toggle_Button_Gadget_Class_Method_GET_STATE()
  179. {
  180.   LVAL self;
  181.   Widget widget_id;
  182.   extern LVAL true;
  183.   
  184.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  185.   xllastarg();
  186.  
  187.   return (XmToggleButtonGadgetGetState(widget_id) ? true : NIL);
  188. }
  189.  
  190.  
  191. /******************************************************************************
  192.  * (send <togglebutton> :SET_STATE <state_p> <notify_p>)
  193.  * ==> returns <togglebutton>.
  194.  * <state_p> -- NIL if button is off, else button is on.
  195.  * <notify_p> -- if not NIL, :xmn_value_changed_callback gets called.
  196.  *
  197.  * void XmToggleButtonSetState (Widget w, Boolean newstate, Boolean notify);
  198.  * void XmToggleButtonGadgetSetState (Widget w, Boolean newstate, Boolean notify);
  199.  ******************************************************************************/
  200. LVAL Xm_Toggle_Button_Widget_Class_Method_SET_STATE()
  201. {
  202.   LVAL self, state_p, notify_p;
  203.   Widget widget_id;
  204.   
  205.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  206.   state_p = xlgetarg();
  207.   notify_p = xlgetarg();
  208.   xllastarg();
  209.  
  210.   XmToggleButtonSetState(widget_id, 
  211.              (state_p) ? TRUE : FALSE,
  212.              (notify_p) ? TRUE : FALSE);
  213.   return (self);
  214. }
  215.  
  216. LVAL Xm_Toggle_Button_Gadget_Class_Method_SET_STATE()
  217. {
  218.   LVAL self, state_p, notify_p;
  219.   Widget widget_id;
  220.   
  221.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  222.   state_p = xlgetarg();
  223.   notify_p = xlgetarg();
  224.   xllastarg();
  225.  
  226.   XmToggleButtonGadgetSetState(widget_id, 
  227.                    (state_p) ? TRUE : FALSE,
  228.                    (notify_p) ? TRUE : FALSE);
  229.   return (self);
  230. }
  231.  
  232.  
  233. /******************************************************************************
  234.  *
  235.  ******************************************************************************/
  236. Wc_ToggleB_Init()
  237. {
  238.   LVAL o_XM_TOGGLE_BUTTON_WIDGET_CLASS;
  239.   LVAL o_XM_TOGGLE_BUTTON_GADGET_CLASS;
  240.   extern LVAL Wcls_Create_Subclass_Of_WIDGET_CLASS(); /* w_classes.c */
  241.   extern      xladdmsg();    /* from xlobj.c */
  242.   
  243.   o_XM_TOGGLE_BUTTON_WIDGET_CLASS =
  244.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_TOGGLE_BUTTON_WIDGET_CLASS",
  245.                      xmToggleButtonWidgetClass);
  246.  
  247.   xladdmsg(o_XM_TOGGLE_BUTTON_WIDGET_CLASS, ":ADD_CALLBACK",
  248.            FTAB_Xm_Toggle_Button_Widget_Class_Method_ADD_CALLBACK);
  249.  
  250.   xladdmsg(o_XM_TOGGLE_BUTTON_WIDGET_CLASS, ":SET_CALLBACK",
  251.            FTAB_Xm_Toggle_Button_Widget_Class_Method_SET_CALLBACK);
  252.  
  253.   xladdmsg(o_XM_TOGGLE_BUTTON_WIDGET_CLASS, ":GET_STATE",
  254.            FTAB_Xm_Toggle_Button_Widget_Class_Method_GET_STATE);
  255.  
  256.   xladdmsg(o_XM_TOGGLE_BUTTON_WIDGET_CLASS, ":SET_STATE",
  257.            FTAB_Xm_Toggle_Button_Widget_Class_Method_SET_STATE);
  258.  
  259.  
  260.   o_XM_TOGGLE_BUTTON_GADGET_CLASS =
  261.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_TOGGLE_BUTTON_GADGET_CLASS",
  262.                      xmToggleButtonGadgetClass);
  263.  
  264.   xladdmsg(o_XM_TOGGLE_BUTTON_GADGET_CLASS, ":ADD_CALLBACK",
  265.            FTAB_Xm_Toggle_Button_Widget_Class_Method_ADD_CALLBACK);
  266.  
  267.   xladdmsg(o_XM_TOGGLE_BUTTON_GADGET_CLASS, ":SET_CALLBACK",
  268.            FTAB_Xm_Toggle_Button_Widget_Class_Method_SET_CALLBACK);
  269.  
  270.   xladdmsg(o_XM_TOGGLE_BUTTON_GADGET_CLASS, ":GET_STATE",
  271.            FTAB_Xm_Toggle_Button_Gadget_Class_Method_GET_STATE);
  272.  
  273.   xladdmsg(o_XM_TOGGLE_BUTTON_GADGET_CLASS, ":SET_STATE",
  274.            FTAB_Xm_Toggle_Button_Gadget_Class_Method_SET_STATE);
  275.  
  276.   s_CALLBACK_SET = xlenter("CALLBACK_SET");
  277. }
  278.